package com.scape.core.service;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

import com.scape.core.model.Document;

@Service
public class ScapeImagesGenerationService 
{

	public void generate(Document document) throws Exception
	{
	    ImageResizeService handler = new ImageResizeService();

	    InputStream in = new ByteArrayInputStream(document.getContent());
	    BufferedImage bi = ImageIO.read(in);
		ImageResizeRequest request = new ImageResizeRequest();
		request.setResizeAction(ImageResizeAction.ALWAYS);
		request.setSourceImage(bi);
		//request.setSourceFilePath(document.getFilename());
	    request.setTargetHeight(1000);
	    request.setTargetWidth(1000);
	    request.setMaintainAspect(true);
	    request.setCropToAspect(false);
	    request.setDestinationFilePath(Document.SAVE_PATH  + "01_output_maintainaspect_nocrop_a.jpg");
	    if (handler.resize(request) == null)
	    	throw new Exception();
	}
}
